package com.freewater.springboot.demo.web.async;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.async.DeferredResult;

@RestController
@RequestMapping("/asyncDemo")
@AllArgsConstructor
@Slf4j
public class AsyncDemoController {

    private BusinessService businessService;

    @GetMapping("/helloAsync")
    @ResponseBody
    public DeferredResult<String> helloAsync(@RequestParam String name) {
        DeferredResult<String> deferredResult = new DeferredResult<>();
        log.info("doSomeBusiness begin");
        businessService.doSomeBusiness(deferredResult, name);
        return deferredResult;
    }
}
